const Cookies = require("cookies")

function loginChecker(req, res, next) {
    console.log("loginCheck");

    var cookies = new Cookies(req, res, {
        keys: ["myblogkeys"]
    });
    const loginok = cookies.get("loginok", {
        signed: true
    })
    console.log("loginok=", loginok);

    if (loginok) {
        next()
    } else {
        res.redirect("/user/login")
    }
}

module.exports = loginChecker